package cn.layou.thread;

import java.util.concurrent.locks.LockSupport;

/**
 *
 * 两个线程，打印A1B2C3....Z26
 *
 * @author layou
 * @date 2021-04-19
 **/
public class T05_ThreadAZeroBOne {
    static String[] words = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
    static String[] numbers = new String[26];
    static {
        for(int i=1; i<=26; i++) {
            numbers[i-1] = String.valueOf(i);
        }
    }

    static Thread t1 = null, t2 = null;

    public static void main(String[] args) {
        t1 = new Thread(() -> {
            for(int i=0; i<words.length; i++) {
                System.out.print(words[i]);
                LockSupport.unpark(t2);
                LockSupport.park();
            }
        });

        t2 = new Thread(() -> {
            for (int i=0; i<numbers.length; i++) {
                LockSupport.park();
                System.out.print(numbers[i]);
                LockSupport.unpark(t1);
            }
        });

        t1.start();
        t2.start();
    }
}
